/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BeerEntryFrame.java
 *
 * Created on Mar 1, 2011, 2:36:31 PM
 */

package gbbmgmt;

import org.jdesktop.application.Action;

import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.table.*;
import java.text.*;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.event.*;

/**
 *
 * @author dchapman
 */
public class BeerEntryFrame extends javax.swing.JFrame {

    //Variables for calculations.
    public ArrayList<String[]> Beers;
    public ArrayList<String[]> Recipes;
    public ArrayList<String[]> Cost;

    //Create Number Formater for displaying numbers.
    public NumberFormat f1 = new DecimalFormat("#0");
    public NumberFormat f2 = new DecimalFormat("#0.00");
    public NumberFormat f3 = new DecimalFormat("#0.000");

    /** Creates new form BeerEntryFrame */
    public BeerEntryFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxBeer = new javax.swing.JComboBox();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jButtonCustLast = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jComboBoxRecipe = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldABV = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldIBU = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSRM = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxCost = new javax.swing.JComboBox();
        jTextFieldNotes = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jCheckBoxInProd = new javax.swing.JCheckBox();
        jButtonSubmit = new javax.swing.JButton();
        jButtonVMRecip = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jButtonUpdate = new javax.swing.JButton();
        jButtonNewBeer = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldBName = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jComboBoxBeer.setName("jComboBoxBeer"); // NOI18N
        jComboBoxBeer.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxBeerPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(BeerEntryFrame.class, this);
        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(BeerEntryFrame.class);
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("PrevRecord")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("NextRecord")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jComboBoxRecipe.setName("jComboBoxRecipe"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldABV.setText(resourceMap.getString("jTextFieldABV.text")); // NOI18N
        jTextFieldABV.setName("jTextFieldABV"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldIBU.setName("jTextFieldIBU"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldSRM.setName("jTextFieldSRM"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jComboBoxCost.setName("jComboBoxCost"); // NOI18N

        jTextFieldNotes.setText(resourceMap.getString("jTextFieldNotes.text")); // NOI18N
        jTextFieldNotes.setName("jTextFieldNotes"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jCheckBoxInProd.setText(resourceMap.getString("jCheckBoxInProd.text")); // NOI18N
        jCheckBoxInProd.setName("jCheckBoxInProd"); // NOI18N

        jButtonSubmit.setAction(actionMap.get("SubBeer")); // NOI18N
        jButtonSubmit.setText(resourceMap.getString("jButtonSubmit.text")); // NOI18N
        jButtonSubmit.setName("jButtonSubmit"); // NOI18N

        jButtonVMRecip.setAction(actionMap.get("OpenRecipeFrame")); // NOI18N
        jButtonVMRecip.setText(resourceMap.getString("jButtonVMRecip.text")); // NOI18N
        jButtonVMRecip.setName("jButtonVMRecip"); // NOI18N

        jButtonExit.setAction(actionMap.get("exitBeer")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jButtonUpdate.setAction(actionMap.get("UpdateBeer")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonNewBeer.setAction(actionMap.get("NewBeer")); // NOI18N
        jButtonNewBeer.setText(resourceMap.getString("jButtonNewBeer.text")); // NOI18N
        jButtonNewBeer.setName("jButtonNewBeer"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldBName.setText(resourceMap.getString("jTextFieldBName.text")); // NOI18N
        jTextFieldBName.setName("jTextFieldBName"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxBeer, 0, 284, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBName, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jCheckBoxInProd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 173, Short.MAX_VALUE)
                        .addComponent(jButtonSubmit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonVMRecip))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxCost, 0, 256, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxRecipe, 0, 294, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldNotes, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldSRM)
                            .addComponent(jTextFieldIBU)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldABV, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNewBeer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 223, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCustLast)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustPrev, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jComboBoxBeer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldBName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBoxRecipe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldABV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldIBU, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jComboBoxCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSRM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldNotes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonVMRecip)
                    .addComponent(jButtonSubmit)
                    .addComponent(jCheckBoxInProd))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonUpdate)
                    .addComponent(jButtonNewBeer)
                    .addComponent(jButtonExit))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxBeerPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxBeerPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxBeer.getSelectedItem().toString();

        DBA.openDBCon();

        for(String s[] : Beers){
            String BrewComp = s[1];

            if (BrewComp.equals(Itm)) {
                DBA.GetBeerData(s[0]);
            }
        }

        DBA.closeDBCon();

        SetData();
    }//GEN-LAST:event_jComboBoxBeerPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BeerEntryFrame().setVisible(true);
            }
        });
    }

    @Action
    public void exitBeer() {
        dispose();
    }

    public void LoadList(){
        //Remove all existing items in combo boxes.
        jComboBoxRecipe.removeAllItems();
        jComboBoxBeer.removeAllItems();
        jComboBoxCost.removeAllItems();

        //Load combo boxes.
        DBA.openDBCon();
        Recipes = DBA.RunSQLQuery("SELECT RID,RName,RRev FROM Recipes");
        Beers = DBA.RunSQLQuery("SELECT BId,BName FROM Beer");
        Cost = DBA.RunSQLQuery("SELECT CostID,CostDesc FROM Cost");

        for(String s[] : Recipes){
            jComboBoxRecipe.addItem(s[0] + ": " + s[1] + " - Rev " + s[2]);
        }

        for(String s[] : Beers){
            jComboBoxBeer.addItem(s[1]);
        }

        for(String s[] : Cost){
            jComboBoxCost.addItem(s[1]);
        }

        //Close Database Connection.
        DBA.closeDBCon();

        LastRecord();
    }

    @Action
    public void LastRecord() {
        jComboBoxBeer.setSelectedIndex(jComboBoxBeer.getItemCount()-1);
        String Itm = jComboBoxBeer.getSelectedItem().toString();

        DBA.openDBCon();

        for(String s[] : Beers){
            String BrewComp = s[1];

            if (BrewComp.equals(Itm)) {
                DBA.GetBeerData(s[0]);
            }
        }

        DBA.closeDBCon();

        SetData();
    }

    public void SetData(){
        //Set Text Fields.
        jTextFieldBName.setText(DBA.BName);
        jTextFieldABV.setText(f2.format(DBA.BAbv));
        jTextFieldIBU.setText(f2.format(DBA.BIbu));
        jTextFieldSRM.setText(Integer.toString(DBA.BSrm));
        jTextFieldNotes.setText(DBA.BNotes);

        //Check Box
        jCheckBoxInProd.setSelected(DBA.InProduction);

        //Set Combo Boxes.
        for(String s[] : Recipes){
            if(s[0].equals(Integer.toString(DBA.RecipeID))){
                jComboBoxRecipe.setSelectedItem(s[0] + ": " + s[1] + " - Rev " + s[2]);
            }
        }

        for(String s[] : Cost){
            if(s[0].equals(Integer.toString(DBA.BCost))){
                jComboBoxCost.setSelectedItem(s[1]);
            }
        }

        //Hide the submit button.
        jButtonSubmit.setVisible(false);
    }

    @Action
    public void FirstRecord() {
        jComboBoxBeer.setSelectedIndex(0);
        String Itm = jComboBoxBeer.getSelectedItem().toString();

        DBA.openDBCon();

        for(String s[] : Beers){
            String BrewComp = s[1];

            if (BrewComp.equals(Itm)) {
                DBA.GetBeerData(s[0]);
            }
        }

        DBA.closeDBCon();

        SetData();
    }

    @Action
    public void PrevRecord() {
        if(jComboBoxBeer.getSelectedIndex() >= 1){
            jComboBoxBeer.setSelectedIndex(jComboBoxBeer.getSelectedIndex()-1);
        }
        String Itm = jComboBoxBeer.getSelectedItem().toString();

        DBA.openDBCon();

        for(String s[] : Beers){
            String BrewComp = s[1];

            if (BrewComp.equals(Itm)) {
                DBA.GetBeerData(s[0]);
            }
        }

        DBA.closeDBCon();

        SetData();
    }

    @Action
    public void NextRecord() {
        if(jComboBoxBeer.getSelectedIndex() <= (jComboBoxBeer.getItemCount() - 2)){
            jComboBoxBeer.setSelectedIndex(jComboBoxBeer.getSelectedIndex()+1);
        }
        String Itm = jComboBoxBeer.getSelectedItem().toString();

        DBA.openDBCon();

        for(String s[] : Beers){
            String BrewComp = s[1];

            if (BrewComp.equals(Itm)) {
                DBA.GetBeerData(s[0]);
            }
        }

        DBA.closeDBCon();

        SetData();
    }

    @Action
    public void UpdateBeer() {
        //Check fields in database and update appropriately.
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify current beer, Continue? " +
                "\n(If this is a new Beer, please select the New Beer Button.)",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();

            //Get current beer id
            String beerID = "";
            String Itm = jComboBoxBeer.getSelectedItem().toString();
            for(String s[] : Beers){
                String BrewComp = s[1];
                if (BrewComp.equals(Itm)) {
                    beerID = s[0];
                }
            }

            //Start query statemetn.
            String query = "UPDATE Beer SET ";

            //Always fill in Beer Name to ensure no comma problems.
            query += ("BName='" + jTextFieldBName.getText() + "'");

            //Check Numbers
            if (!jTextFieldABV.getText().equals(f2.format(DBA.BAbv))){
                query += (", BAbv='" + jTextFieldABV.getText() + "'");
            }
            if (!jTextFieldSRM.getText().equals(Integer.toString(DBA.BSrm))){
                query += (", BSrm='" + jTextFieldSRM.getText() + "'");
            }
            if (!jTextFieldIBU.getText().equals(f2.format(DBA.BIbu))){
                query += (", BIbu='" + jTextFieldIBU.getText() + "'");
            }
            if(!jTextFieldNotes.getText().equals(DBA.BNotes)){
                query += (", BNotes='" + jTextFieldNotes.getText() + "'");
            }

            //Check box update.
            if(jCheckBoxInProd.isSelected() != DBA.InProduction){
                query += (", InProduction='" + Integer.toString((jCheckBoxInProd.isSelected())?1:0) + "'");
            }

            //Check Recipe ID.
            for(String s[] : Recipes){
                if((s[0] + ": " + s[1] + " - Rev " + s[2]).equals(jComboBoxRecipe.getSelectedItem().toString())){
                    if(!s[0].equals(Integer.toString(DBA.RecipeID))){
                        query += (", RecipeID='" + s[0] + "'");
                    }
                }
            }

            //Check BCost ID.
            for(String s[] : Cost){
                if((s[1]).equals(jComboBoxCost.getSelectedItem().toString())){
                    if(!s[0].equals(Integer.toString(DBA.BCost))){
                        query += (", BCost='" + s[0] + "'");
                    }
                }
            }

            //End query statement.
            query += " WHERE BId = '" + beerID + "'";

            DBA.RunSQLUpdateQuery(query);

            //Update beer display in combo box.
            DBA.GetBeerData(beerID);
            Beers.clear();
            Beers = DBA.RunSQLQuery("SELECT BId,BName FROM Beer");
            jComboBoxBeer.removeAllItems();
            jComboBoxBeer.revalidate();
            for(String s[] : Beers){
                jComboBoxBeer.addItem(s[1]);
            }
            jComboBoxBeer.setSelectedItem(DBA.BName);

            DBA.closeDBCon();

            SetData();
        }
    }

    @Action
    public void OpenRecipeFrame() {
        Actions.CallFunction("Recipes");
    }

    @Action
    public void NewBeer() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will create a new beer, Continue? ",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            //Show submit button
            jButtonSubmit.setVisible(true);

            //Hide other buttons.
            jComboBoxBeer.setVisible(false);
            jButtonCustFirst.setVisible(false);
            jButtonCustLast.setVisible(false);
            jButtonCustNext.setVisible(false);
            jButtonCustPrev.setVisible(false);
            jButtonUpdate.setVisible(false);
            jButtonNewBeer.setVisible(false);

            //Clear out all fields.
            jComboBoxCost.setSelectedIndex(0);
            jComboBoxRecipe.setSelectedIndex(0);

            jTextFieldABV.setText("0.00");
            jTextFieldBName.setText("");
            jTextFieldIBU.setText("0.00");
            jTextFieldNotes.setText("");
            jTextFieldSRM.setText("0");

            jCheckBoxInProd.setSelected(true);
        }
    }

    @Action
    public void SubBeer() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will submit this beer to the database, Continue? ",
                "Warning",JOptionPane.WARNING_MESSAGE);
        if (response == 0){
             DBA.openDBCon();

            String query = "'" +
                jTextFieldABV.getText() + "','" +
                jTextFieldBName.getText() + "','" +
                jTextFieldIBU.getText() + "','" +
                jTextFieldNotes.getText() + "','" +
                jTextFieldSRM.getText() + "','" +
                Integer.toString((jCheckBoxInProd.isSelected())?1:0) + "','";

            //Add in the combo boxes.
            for(String s[] : Recipes){
                if((s[0] + ": " + s[1] + " - Rev " + s[2]).equals(jComboBoxRecipe.getSelectedItem().toString())){
                    query += s[0] + "','";
                }
            }

            //Check BCost ID.
            for(String s[] : Cost){
                if((s[1]).equals(jComboBoxCost.getSelectedItem().toString())){
                    query += s[0] + "'";
                }
            }

            //Fill in fields.
            String fields = "BAbv,BName,BIbu,BNotes,BSrm,InProduction,RecipeID,BCost";

            //Insert new data.
            DBA.RunSQLInsertQuery("Beer",fields,query);

            //Update beer display in combo box.
            Beers.clear();
            Beers = DBA.RunSQLQuery("SELECT BId,BName FROM Beer");
            jComboBoxBeer.removeAllItems();
            jComboBoxBeer.revalidate();
            for(String s[] : Beers){
                jComboBoxBeer.addItem(s[1]);
            }

            //Close connection.
            DBA.closeDBCon();

            //Set visibilities.
            jButtonSubmit.setVisible(false);

            //Hide other buttons.
            jComboBoxBeer.setVisible(true);
            jButtonCustFirst.setVisible(true);
            jButtonCustLast.setVisible(true);
            jButtonCustNext.setVisible(true);
            jButtonCustPrev.setVisible(true);
            jButtonUpdate.setVisible(true);
            jButtonNewBeer.setVisible(true);

            //Show the new record.
            LastRecord();
        }
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonNewBeer;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JButton jButtonVMRecip;
    private javax.swing.JCheckBox jCheckBoxInProd;
    private javax.swing.JComboBox jComboBoxBeer;
    private javax.swing.JComboBox jComboBoxCost;
    private javax.swing.JComboBox jComboBoxRecipe;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextFieldABV;
    private javax.swing.JTextField jTextFieldBName;
    private javax.swing.JTextField jTextFieldIBU;
    private javax.swing.JTextField jTextFieldNotes;
    private javax.swing.JTextField jTextFieldSRM;
    // End of variables declaration//GEN-END:variables

}
